package ControlLayer;
import ModelLayer.*;
import java.util.ArrayList;
//model layer package has to be imported

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{

    private AddressBook ab;

    /**
     * the constructor for the class
     */
    public AddressCtr(/*---*/)
    {
        ab = new AddressBook();
    }

    /**
     * this method returns a person through a search
     * @param name
     * @return p
     */
    public Person getPerson(String name)
    {
        Person p = ab.readPerson(name);
        return p;
    }

    /**
     * this method makes it possible to create a new person
     * and add it to the list p. can be used from UI layer
     * @param id, name, address, postalcode, town, phoneNo
     */
    public void createPerson(int ID, String name, String address, String postalCode, String town, int phoneNo)
    {
        Person p = new Person(ID, name, address, postalCode, town, phoneNo);
        ab.addPerson(p);
    }

    /**
     * this method makes it possible to remove a person from the list through a
     * search. can be used in UI layer
     * @param name
     */
    public void removePerson(String name)
    {
        Person p = ab.findPerson(name);
        ab.removePerson(p);
    }

    /**
     * this method makes it possible to update a person
     * @param id, name, address, postalCode, town, phoneNo
     */
    //  this method works, but we can not chose which person we want to update
    //  a search method is needed for that purpose  
    public void updatePerson(int ID, String name, String address, String postalCode, String town, int phoneNo)
    {
        ab.updatePerson(ID, name, address, postalCode, town, phoneNo);
    }

    /**
     * this method returns the AddressBook list
     * @return p
     */
    public ArrayList<Person> listAllPersons()
    {
        ArrayList<Person> p = ab.listAllPersons();
        return p;
    }
}
